﻿using MediatR;
using SlaughterItem.Common.Domains.Check_Ins;
using SlaughterItem.Common.Domains.ListWeek2;
using SlaughterItem.Common.Domains.UPCTable;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.BasicSettings
{
    public class SplitRequisSuretenHandler : IRequestHandler<SplitRequisSuretenCommend, Result>
    {
        private readonly IBaseRepositoryGet<SplitRequis> SplitRequis;
        private readonly IBaseRepositoryGet<Product> Product;
        private readonly IBaseRepositoryGet<UPCData> UPCData;

        public SplitRequisSuretenHandler(IBaseRepositoryGet<SplitRequis> SplitRequis, IBaseRepositoryGet<Supplier> Supplier
            , IBaseRepositoryGet<Product> Product, IBaseRepositoryGet<UPCData> UPCData)
        {
            this.SplitRequis = SplitRequis;
            this.Product = Product;
            this.UPCData = UPCData;
        }

        public async Task<Result> Handle(SplitRequisSuretenCommend request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = (from a in SplitRequis.GetAll()
                            join b in Product.GetAll() on a.ProductId equals b.ProductId
                            join d in UPCData.GetAll() on a.MarkId equals d.GoodsMinuteId
                            where a.IsDelete == false
                            select new
                            {
                                a.SplitRequisId,
                                a.SplitRequisTime,
                                a.DepotId,
                                a.SplitRequisNum,
                                a.SplitRequisGrossWeight,
                                a.SplitRequisTares,
                                a.SplitRequisWeight,
                                a.SplitRequisRemark,
                                b.ProductId,
                                b.ProductName,
                                d.GoodsMinuteId,
                                d.UPCDataName,

                            }).ToList();

                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "查询成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }


    }
}
